package com.example.yrdev.ordering_system.Database;

import android.content.Context;

import com.example.yrdev.ordering_system.Utils.GlobalFunction;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * Created by luke on 10/5/16.
 */

public class PurchasedItemTB {//购买过的商品数据库

    public static   final String DH_TABLE_NAME = "purchased_item";

    public static   final String  item_CardID="item_CardID";
    public static   final String  item_TicketID="item_TicketID";
    public static   final String  item_ID="item_ID";//商品编号
    public static   final String  item_name="item_Name";//商品名称
    public static  final String  item__amount="item__amount";//数量
    public static  final String  item_totalPrice="item_totalPrice";
    public static  final String  item_purchDate="item_purchDate";
    public static  final String  item_purchTime="item_purchTime";
    public static  final String  item_payMode="item_payMode";//0 现金,1 信用卡,2 签单,3 会员卡,4 礼劵, 8 - 退货  会员卡,9 - 退货  现金
    public static  final String item_Discount="item_Discount";
    public static  final String item_PrimeCost="item_primeCost";//进货价
    public  static final String item_SaleCost="item_saleCost";//会员价
    public static  final String item_EmployeID="EmployeeID";




    Context context;


    public  static final String DH_CREATE_TABLE="CREATE TABLE " + DH_TABLE_NAME + "( " +item_CardID +" TEXT," + item_TicketID + " TEXT," + item_ID + " TEXT," + item_name + " TEXT, " + item__amount + " INTEGER,"
            + item_totalPrice + " INTEGER," + item_purchDate + " TEXT," +item_purchTime+" TEXT,"+ " item_payMode "+ " INTEGER, " + " item_Discount " +"FLOAT,"
            + " item_primeCost "+"INTEGER,"+" item_saleCost "+"INTEGER,"+" EmployeeID "+"TEXT"+ ")";
    public static void insertRecord(Context context,Item item){

        DingHanDB.getInstance(context).insert(DH_TABLE_NAME,item);

    }




    public static ArrayList<Item> getPurchasedHistory(Context context){



       return DingHanDB.getInstance(context).getPurchasedItemHistory();

    }

    public static ArrayList<Item> getPurchasedHistoryBaseOnPurchaseType(Context context,Integer purchaseType){

        return DingHanDB.getInstance(context).getPurchasedItemHistoryBaseOnPurchaseType(purchaseType);

    }


    public static class Item implements Serializable{
          String  card_ID="0";
         String  item_ID="item_ID";//商品编号
         String   item_TicketID="";//发票号
         String  item_name;//商品名称
         Integer  item_amount;//数量
         Integer  item_totalPrice;

         String  item_purchDate;//购物日期

        String  item_purchTime;//购物时间

         Integer  item_payMode=0;//0 现金,1 信用卡,2 签单,3 会员卡,4 礼劵, 8 - 退货  会员卡,9 - 退货  现金
         double discount=0.1;
         char primeCost;//进货价
        double saleCost;//会员价
         String EmployeeID="";
          String payModeText="现金";
        Integer totalPrice;

        public Item(String item_ID){

        this.item_ID=item_ID;

        }

    public  void setItem_ID(String item_ID) {
        this.item_ID=item_ID;

    }

    public String getItem_ID() {
       return item_ID;

    }

        public void setCard_ID(String card_ID) {
            this.card_ID = card_ID;
        }

        public String getCard_ID() {
            return card_ID;
        }



        public void setItem_name(String item_name) {
        this.item_name = item_name;
    }

    public String getItem_name() {
        return item_name;
    }

    public Integer getItem_amount() {
        return item_amount;
    }

        public double getSaleCost() {
            return saleCost;
        }

        public void setItem_amount(Integer item_amount) {
        this.item_amount = item_amount;
    }

    public void setSaleCost(Integer saleCost) {
        this.saleCost = saleCost;
    }

    public void setItem_payMode(Integer item_payMode) {
        this.item_payMode = item_payMode;
    }

    public Integer getItem_payMode() {
        return item_payMode;
    }

    public String getItem_purchDate() {
        if (item_purchDate==null){
            item_purchDate=GlobalFunction.getCurrentDate();


        }

       return item_purchDate;

    }


        public String getItem_purchTime() {

            if (item_purchTime==null){

                item_purchTime=GlobalFunction.getCurrentTime();

            }

            return item_purchTime;
        }

        public void setItem_TicketID(String item_TicketID) {
            this.item_TicketID = item_TicketID;
        }

        public String getItem_TicketID() {
            return item_TicketID;
        }

        public String getPayModeText() {
        switch (item_payMode){
            case 3:
                payModeText="刷卡";

        }
        return payModeText;
    }

        public Double getTotalPrice() {

        return item_amount*saleCost;

    }
}



}
